package jTopaz;

import org.globus.ftp.GridFTPClient;
import org.ietf.jgss.GSSCredential;
import org.globus.myproxy.MyProxy;

/**
Handles logging onto a gridFTP server.
*/
public class LoginThread extends Thread {
	
	private GridFTPClient client;
	private GSSCredential cred;
	private String host;
	private String status;
	
	/**
	@param host the host to connect to.
	@param cred the cred for authentication
	*/
	public LoginThread(String host, GSSCredential cred) {
	
		try {
			this.host = host;
			this.cred = cred;
		}
		catch (Exception e) {
			System.out.println(e);
		}
	}	
	
	/**
	Creates a new GridFTPClient with the given host on port 2811 using the cred.
	*/
	public void run() {
		try {
			
			client = new GridFTPClient(host, 2811);
			System.out.println(cred.getRemainingLifetime());
			client.authenticate(cred);
			
			client.setPassive();
			client.setLocalActive();
	    	
	    	status = "success";
		
		}
		catch (Exception e) {
			status = "failed";
			System.out.println(e);
		}
	}
	
	/**
	Get the status of the login.
	@return "success" if able to log in. "failed" if there was a problem.
	*/
	public String getStatus() {
		return status;
	}
	
	/**
	@return the client created during the execution of the thread.
	*/
	public GridFTPClient getClient() {
		return client;
	}

}